package com.quizzer.web.controller.question;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.quizzer.system.dto.question.category.CategoryAddDto;
import com.quizzer.system.dto.question.category.CategoryOutputDto;
import com.quizzer.system.dto.question.category.CategoryQueryDto;
import com.quizzer.system.dto.question.category.CategoryUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quizzer.common.annotation.Log;
import com.quizzer.common.core.controller.BaseController;
import com.quizzer.common.core.domain.AjaxResult;
import com.quizzer.common.enums.BusinessType;
import com.quizzer.system.domain.Category;
import com.quizzer.system.service.ICategoryService;
import com.quizzer.common.utils.poi.ExcelUtil;
import com.quizzer.common.core.page.TableDataInfo;

/**
 * 小类别Controller
 *
 * @author ruoyi
 * @date 2025-10-07
 */
@Api(tags = "小类别接口")
@RestController
@RequestMapping("/question/category")
public class CategoryController extends BaseController
{
    @Autowired
    private ICategoryService categoryService;

    /**
     * 查询小类别列表
     */
    @ApiOperation("查询小类别列表")
    @PreAuthorize("@ss.hasPermi('question:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(CategoryQueryDto category)
    {
        startPage();
        List<CategoryOutputDto> list = categoryService.selectCategoryList(category);
        return getDataTable(list);
    }

    /**
     * 导出小类别列表
     */
//    @ApiOperation("导出小类别列表")
//    @PreAuthorize("@ss.hasPermi('question:category:export')")
//    @Log(title = "小类别", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Category category)
//    {
//        List<Category> list = categoryService.selectCategoryList(category);
//        ExcelUtil<Category> util = new ExcelUtil<Category>(Category.class);
//        util.exportExcel(response, list, "小类别数据");
//    }

    /**
     * 获取小类别详细信息
     */
    @ApiOperation("获取小类别详细信息")
    @PreAuthorize("@ss.hasPermi('question:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(categoryService.selectCategoryById(id));
    }

    /**
     * 新增小类别
     */
    @ApiOperation("新增小类别")
    @PreAuthorize("@ss.hasPermi('question:category:add')")
    @Log(title = "小类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryAddDto category)
    {
        return toAjax(categoryService.insertCategory(category));
    }

    /**
     * 修改小类别
     */
    @ApiOperation("修改小类别")
    @PreAuthorize("@ss.hasPermi('question:category:edit')")
    @Log(title = "小类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryUpdateDto category)
    {
        return toAjax(categoryService.updateCategory(category));
    }

    /**
     * 删除小类别
     */
    @ApiOperation("删除小类别")
    @PreAuthorize("@ss.hasPermi('question:category:remove')")
    @Log(title = "小类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(categoryService.deleteCategoryByIds(ids));
    }
}
